package com.larissa.android.note;

import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider;

import com.larissa.android.note.databinding.FragmentNoteBinding;

import java.util.ArrayList;
import java.util.UUID;

public class NoteFragment extends Fragment {
    private static final String TAG="NoteFragment";
    private Note mNote;
    private FragmentNoteBinding mFragmentNoteBinding;

    @Override
    public void onAttach(Context context){
        super.onAttach(getContext());
        Log.d(TAG,"onAttach() called");
    }

    @Override
    public void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
//        Log.d(TAG,"onCreate() called");

        mNote=new Note();
        mNote.setTitle(NoteFragmentArgs.fromBundle(getArguments()).getNoteTitle());
        mNote.setContent(NoteFragmentArgs.fromBundle(getArguments()).getNoteContent());
        mNote.setNoteLog(NoteFragmentArgs.fromBundle(getArguments()).getNoteLog());

    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
        super.onCreateView(inflater,container,savedInstanceState);
        Log.d(TAG,"onCreateView() called");
        mFragmentNoteBinding=FragmentNoteBinding.inflate(inflater,container,false);
        // 用数据绑定实现了，所以这些代码可以注释掉了。
//        mFragmentNoteBinding.noteTitle.setText(mNote.getTitle());
//        mFragmentNoteBinding.noteContent.setText(mNote.getContent());
//        mFragmentNoteBinding.noteLog.setText(mNote.getNoteLog());
        View view=mFragmentNoteBinding.getRoot();
        ActionBar actionBar=((AppCompatActivity) getActivity()).getSupportActionBar();
        actionBar.setTitle(TAG);
        return view;
    }

    @Override
    public void onViewCreated(View view,Bundle savedInstanceState){
        super.onViewCreated(view,savedInstanceState);
        Log.d(TAG,"onViewCreated() called");
        mFragmentNoteBinding.setNote(mNote);
    }

    @Override
    public void onViewStateRestored(Bundle savedInstanceState){
        super.onViewStateRestored(savedInstanceState);
        Log.d(TAG,"onViewStateRestored() called");
    }

    @Override
    public void onStart(){
        super.onStart();
        Log.d(TAG,"onStart() called");
    }

    @Override
    public void onResume(){
        super.onResume();
        Log.d(TAG,"onResume() called");
    }

    @Override
    public void onPause(){
        super.onPause();
        Log.d(TAG,"onPause() called");
    }

    @Override
    public void onStop(){
        super.onStop();
        Log.d(TAG,"onStop() called");
    }

    @Override
    public void onDestroyView(){
        super.onDestroyView();
        Log.d(TAG,"onDestroyView() called");
        mFragmentNoteBinding=null;
    }

    @Override
    public void onDestroy(){
        super.onDestroy();
        Log.d(TAG,"onDestroy() called");
    }

    @Override
    public void onDetach(){
        super.onDetach();
        Log.d(TAG,"onDetach() called");
    }
}
